package com.example.agent_intelligent_companion;

import android.os.Bundle;
import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class DatabaseActivity extends Activity {

	SQLiteOpenHelper dbHelper;
	SQLiteDatabase database;
	
	// Variables the mac-address and location from the text.
	EditText mac;
	EditText loc;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_database);
		
		// set up the database
		dbHelper = new AICDatabase(this);
		database = dbHelper.getWritableDatabase();
		
		// Get the mac and location text.
		mac = (EditText)findViewById(R.id.macText);
		loc = (EditText)findViewById(R.id.locationText);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.database, menu);
		return true;
	}
	
	
	// Method that gets called when the update button gets clicked.
	public void UpdateDatabase(View view)
	{
		ContentValues cv = new ContentValues();
		cv.put("mac_address", mac.getText().toString());
		cv.put("location", loc.getText().toString());
		
		database.insert("users", null, cv);
		
		Log.i("UpdateDB", "Updated Correctly");
	}

}
